﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace ExamSharedClasses {
    /// <summary>
    /// (k) Der Antworttyp, der auf den Fragentyp QuestionTypeSingleMultiple passt
    /// </summary>
    [Serializable()]
    public class AnswerTypeSingleMultiple : Answer {
        new public const string TABLENAME = "answer_type_single_multiple";
        public const string ANSWER_USER_ANSWER = "answer_user_answer";

        public int AnswerUserAnswer { get; set; }

        public AnswerTypeSingleMultiple()
            : base() {
            this.AnswerUserAnswer = -1;
        }
        public AnswerTypeSingleMultiple( int examId )
            : this() {
            this.AnswerExamId= examId;
        }
        public AnswerTypeSingleMultiple( Answer answer )
            : base( answer ) {
            this.AnswerUserAnswer = -1;
        }
        public AnswerTypeSingleMultiple( int examId, Question question ) : this() {
            AnswerExamId = examId;
            AnswerQuestion = question;
        }

        public override string ToMoreDetailedString() {
            StringBuilder sb = new StringBuilder( base.ToMoreDetailedString() + "AnswerTypeSingleMultiple: " );
            sb.Append( "ANSWER: " + AnswerUserAnswer + '\n' );
            return sb.ToString();
        }
        public override string ToString() {
            return "angekreuzt: " + Tools.EnumerateLeftToRightPositionsOfPowersOfTwo( AnswerUserAnswer ) + '\n';
        }
        public override int GetAchievedPoints( int maxPointsInt ) {
            double maxPoints = maxPointsInt, achievedPoints = 0.0;
            QuestionTypeSingleMultiple qtsm = ( QuestionTypeSingleMultiple )AnswerQuestion;
            if ( qtsm.QuestionRightAnswer == AnswerUserAnswer ) {
                // dann  max. Punkte hinzurechnen
                achievedPoints += ( maxPoints );
            }
            return ( int )achievedPoints;
        }
        public override bool HasSetAnswer() {
            return ( AnswerUserAnswer != -1 );
        }
        public override void SetDefaultAnswer() {
            AnswerUserAnswer = 0;
        }
        public override bool HasEmptyAnswer() {
            return !HasSetAnswer();
        }

    }
}
